package cp4.resp;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

public class LoginServlet extends HttpServlet {
    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        // 获取提交的参数
        String name = req.getParameter("username");
        String pass = req.getParameter("password");

        resp.setContentType("text/html;charset=utf-8");
        resp.setCharacterEncoding("utf-8");

        if("admin".equalsIgnoreCase(name) && "admin".equalsIgnoreCase(pass)){
            // 判断输入的是否正确
            // 登录成功 跳转到login success
            resp.sendRedirect("/login-success.html");
        }else{
            PrintWriter out = resp.getWriter();
            out.println("用户名或者密码错误");
        }
    }
}
